﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;

namespace QuanLyDiemHocSinh
{
    public partial class Test_Gridview : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
           if (!IsPostBack)
            {
                Fill_Data();
            }
        }
        protected void BindGridview()
        {
            using (SqlConnection con = new SqlConnection("Server=.\\SqlExpress;Integrated Security=True;Database=QuanLyDiem"))
            {
                con.Open();
                SqlCommand cmd = new SqlCommand("Select MonHoc.TenMonHoc,MonHoc.HeSo,BangDiemCon.MaLoaiDiem,BangDiemCon.Diem from MonHoc,BangDiemCon where MonHoc.MaMonHoc=BangDiemCon.MaMonHoc", con);
                SqlDataReader dr = cmd.ExecuteReader();
                GridView1.DataSource = dr;
                GridView1.DataBind();
                con.Close();
                
            }
        }
        public void Fill_Data()
        {
            SqlConnection con = new SqlConnection("Server=.\\SqlExpress;Integrated Security=True;Database=QuanLyDiem");
            SqlCommand cmd = new SqlCommand("Select MonHoc.TenMonHoc, BangDiemCon.Diem from MonHoc,BangDiemCon where MonHoc.MaMonHoc=BangDiemCon.MaMonHoc", con);
            con.Open();
            SqlDataAdapter da = new SqlDataAdapter(cmd.CommandText, con);
            DataTable tb = new DataTable();
            da.Fill(tb);
            rpt_BangDiem.DataSource = tb;
            rpt_BangDiem.DataBind();
        }
    }
}